package com.hoyue.utils;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.commons.dbutils.QueryRunner;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author Hoyue_network1
 * @version 1.0
 * Creat by 2018/8/7 1:09
 */
public class C3P0Utils {

	// 获得c3p0连接池对象
	private static DataSource ds = new ComboPooledDataSource("MySQL");

	// 获得数据库连接对象
	public static Connection getConnection() throws SQLException {
		return ds.getConnection();
	}

	// 返回连接池对象
	public static DataSource getDataSource() {
		return ds;
	}

	public static QueryRunner getQueryRunner() {
		QueryRunner qr =  new QueryRunner(ds);
		return qr;
	}
}
